package snu.bi.MSAgent;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class menu_item {
	String name, cate1, cate2, cate3, unit;	
	double cal;
	int id;
	
	menu_item(int i, String c1, String c2, String c3, String n, double ca, String u ) {
		id = i; cate1 = c1; cate2 = c2; cate3 = c3; name = n; cal = ca; unit = u;	
	}
	menu_item(Cursor c) {
		c.moveToFirst();
		id = c.getInt(0);
		cate1 = c.getString(1);
		cate2 = c.getString(2);
		cate3 = c.getString(3);
		name = c.getString(4);
		cal = c.getDouble(5);
		unit = c.getString(6);
	}
	String getid() {
		return Integer.toString(id);
	}
	String getcal() {
		return Double.toString(cal);
	}
}
class menuAdapter extends ArrayAdapter<menu_item> {
	ArrayList<menu_item> items;
	
	public menuAdapter (Context context, int textViewResourceId, ArrayList<menu_item> objects) {
		super(context, textViewResourceId, objects);
		// TODO Auto-generated constructor stub
		items = objects;		
	}
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		if(v == null) {
			LayoutInflater vi = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = vi.inflate(R.layout.menu_item_row, null);
		}
		menu_item m = items.get(position); 
		if (m != null) {
			TextView tv_name = (TextView) v.findViewById(R.id.menu_row_name);
			TextView tv_cate = (TextView) v.findViewById(R.id.menu_row_cate);
			TextView tv_cal = (TextView) v.findViewById(R.id.menu_row_cal);
			
			tv_name.setText(m.name);
			tv_cate.setText(m.cate1+">"+m.cate2+">"+m.cate3);
			tv_cal.setText(m.getcal()+" kcal");
		}
		return v;
	}
	
	
}
class menuInputAdapter extends ArrayAdapter<String> {
	ArrayList<String> items;
	
	public menuInputAdapter (Context context, int textViewResourceId, ArrayList<String> objects) {
		super(context, textViewResourceId, objects);
		// TODO Auto-generated constructor stub
		items = objects;		
	}
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		if(v == null) {
			LayoutInflater vi = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = vi.inflate(R.layout.menuinput_row, null);
		}
		String m = items.get(position); 
		if (m != null) {
			TextView tv_name = (TextView) v.findViewById(R.id.menuinput_row_name);
			tv_name.setText(m);			
		}
		return v;
	}
	
	
}
